﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using EzDesk.EzAppApi.Utility;

namespace EzDesk.EzAppApi.Web.Utility.Attributes
{
    /// <summary>
    /// 对方法进行AppSession的验证
    /// </summary>
    public class EzDeskAppSessionAuthorizeAttribute : AuthorizeAttribute
    {
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            bool isAppSesionCorrect = true; 
            try
            {
                EzDeskAppApiHelper.AppSessionHelper.GetCurrentSession();
            }
            catch (Exception /*ex*/)
            {
                isAppSesionCorrect = false;
            }

            if (!isAppSesionCorrect)
            {
                filterContext.Result = new ViewResult() { ViewName = "Error" };                
            }
        }
    }
}
